package com.wsoft.im.manager;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wsoft.constant.redis.ImRedisConstant;
import com.wsoft.constant.redis.RedisKeyConstant;
import com.wsoft.core.annotation.GetRedisCache;
import com.wsoft.core.service.RedisService;
import com.wsoft.im.entity.ImGroupEntity;
import com.wsoft.im.mapper.ImGroupMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @Author z001
 * @Date 2025/1/14 09:29
 */
@Service
public class ImGroupManager extends ServiceImpl<ImGroupMapper, ImGroupEntity> {

    @Resource
    private RedisService redisService;

    /**
     * 移除群
     * @param groupId
     * @return
     */
    public boolean removeById(Long groupId){
        return super.removeById(groupId);
    }


    /**
     * 修改群组信息
     * @param entity
     * @return
     */
    @Override
    public boolean updateById(ImGroupEntity entity){
        boolean b = super.updateById(entity);
        if(b){
            redisService.del(ImRedisConstant.GROUP_INFO + entity.getId());
        }
        return b;
    }


    @GetRedisCache(type = ImRedisConstant.GROUP_INFO,
            expire_sec = RedisKeyConstant.Cms.EXPIRED,
            value = RedisKeyConstant.REDIS_SELF)
    public ImGroupEntity getById(Long id){
        return super.getById(id);
    }
}
